package com.ybybh.gamecenter.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Random;

@Controller
public class FingerGuessGameController {
    private static String[]  fgs = {"st","jz","b"};
    private static Random random = new Random();
    private static String resultMessage = "";
    private static String zjfg = "wh";


    @RequestMapping("/fgplay")
    public ModelAndView  toFgPlay(String wjfg) {
        int index = random.nextInt(3);
        zjfg = fgs[index];
        if(wjfg.equals("st")){
            if (zjfg.equals("st")){
                resultMessage = "平局了！！";
            }else if (zjfg.equals("jz")){
                resultMessage = "玩家胜利了！！";
            }else if (zjfg.equals("b")){
                resultMessage = "电脑胜利了！！";
            }
        }else if (wjfg.equals("jz")){
            if (zjfg.equals("st")){
                resultMessage = "电脑胜利了！！";
            }else if (zjfg.equals("jz")){
                resultMessage = "平局了！！";
            }else if (zjfg.equals("b")){
                resultMessage = "玩家胜利了";
            }
        }else if (wjfg.equals("b")){
            if (zjfg.equals("st")){
                resultMessage = "玩家胜利了！！";
            }else if (zjfg.equals("jz")){
                resultMessage = "电脑胜利了！！";
            }else if (zjfg.equals("b")){
                resultMessage = "平局了！！";
            }

        }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("resultMessage", resultMessage);
        modelAndView.addObject("wjfg", wjfg+".jpg");
        modelAndView.addObject("zjfg", zjfg+".jpg");
        modelAndView.setViewName("fingerguess");
        return modelAndView;
    }

    @RequestMapping("/fg")
    public ModelAndView toFGHtml() {
        resultMessage = "";
        zjfg = "wh";
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("resultMessage", resultMessage);
        modelAndView.addObject("wjfg", "wh.jpg");
        modelAndView.addObject("zjfg", zjfg+".jpg");
        modelAndView.setViewName("fingerguess");
        return modelAndView;
    }

}
